const express = require('express')
const bodyParser = require('body-parser')

const router = require('./router/base.js')

const app = express()



app.use(bodyParser.urlencoded({
  extends: true
}))

//设置跨域访问
app.all('*', (req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  res.header("Content-Type", "application/json;charset=utf-8");
  next()
})

//  使用路由 /index 是路由指向名称
app.use(`/api`,router)


//配置服务端口
const server = app.listen(3000, () => {
  const hostname = 'localhost';
  const port = 3000;
  console.log(`Server running at http://${hostname}:${port}/`)
})
